package com.conversationboard.batch.jobs.bans;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import com.conversationboard.cache.BannedUserCache;
import com.conversationboard.database.BatchQueries;
import com.conversationboard.database.Database;

public class RemoveTemporaryBans implements Job {

	public void execute(JobExecutionContext arg0) throws JobExecutionException {

		Connection connection = null;

		try {

			connection = Database.getConnection();

			PreparedStatement statement = connection.prepareStatement(BatchQueries.REVOKE_TEMPORARY_BANS);
			statement.executeUpdate();

			BannedUserCache.refresh();
			
		} catch (SQLException e) {
			throw new JobExecutionException(e);
		} finally {
			try {
				Database.close(connection);
			} catch (SQLException e) {
				throw new JobExecutionException(e);
			}
		}

	}

}
